<?php
namespace app\admin\controller;

class User extends Base{

	public function _initialize(){
		parent::_initialize();
		$user_type = $this->_get('user_type');
	}
	public function index(){
		return parent::index('', $where, 'create_time desc');
	}
	// 修改用户密码
	public function win_set_password(){
		$user_id = $this->_get('user_id', '对不起，您的操作有误！');
		$model   = model('User');
		$info    = $model->where(array('user_id' => $user_id))->find();
		if(!$info){
			$this->error('对不起，您的操作有误！');
		}
		if($this->isPost()){
			$password   = $this->_post('password', '密码不能为空！');
			$repassword = $this->_post('repassword', '确认密码不能为空！');
			if($password != $repassword){
				$this->error('两次密码不一致！');
			}

			$password_md5 = password_md5_one($info['user_id'], $password);
			$model->where(array('user_id' => $user_id))->update(array('password' => $password_md5));

			$this->success('修改成功！', '');
		}
		$this->assign('info', $info);
		return $this->view();
	}
	// 设置状态
	public function set_status(){
		$user_id = $this->_get('user_id', '对不起，您的操作有误！');
		$model   = model('User');
		$status  = $model->where(array('user_id' => $user_id))->value('status');

		// 更新用户状态
		$model->where(array('user_id' => $user_id))->update(array('status' => $status ? 0 : 1));
		// 禁用时清空TOKEN登录时间
		if($status){
			db('UserToken')->where(array('user_id' => $user_id))->update(array('create_time' => 0));
		}
		$this->success('设置成功！');
	}
}